class demo { public static void main(String args[]) { Person a=new Person("Amit Jain","Amravati"); a.showData(); Employee e; e=new Employee("Nitin Joshi","Nagpur","Clerk",257005000); e.showData(); e.payment(); Worker w; w=new Worker("Raja","Raipur",500,20); w.showData(); w.payment(); } } class Person { protected String name,city; public Person(String nm,String ct) { name=nm; city=ct; } public void showData() { System.out.println("Name is "+name); System.out.println("City is "+city); } } class Employee extends Person { protected String job ; protected int salary , advance ; public Employee(String nm,String ct,String jb,int sl,int adv) { super(nm,ct); job=jb; salary=sl; advance=adv; } public void showData() { super.showData(); System.out.println("Job is "+job); System.out.println("Salary is "+salary); } public void payment() { int p=salary–advance; System.out.println("Payment is "+p); } } class Worker extends Person { protected int wages,wdays; public Worker(String nm,String ct,int wg,int wd) { super(nm,ct); wages=wg; wdays=wd; } public void showData() { super.showData(); System.out.println("Wages is "+wages); System.out.println("Wdays is "+wdays); } public void payment() { int p=wages*wdays; System.out.println("Payment is "+p); } }
Name is Amit Jain City is Amravati Name is Nitin Joshi City is Nagpur Job is Clerk Salary is 25700 Advance is 5000 Payment is 20700 Name is Raja City is Raipur Wages is 500 Wdays are 20 Payment is 10000